﻿using System;
using System.Collections.Generic;
using System.Text;
using static System.Console;

namespace IllustratedCsharp7_ch9
{
    class chapt9_15LimitationsOfOperatorOverloading
    {
        static void Show(string message, MyType tv)
        {
            WriteLine($"{message} {tv.X}");
        }

        static void _Main()
        {
            MyType tv = new MyType(10);
            WriteLine("Pre-increment");
            Show("Before   ",tv);
            Show("Returned   ", ++tv);
            Show("After   ", tv);
            WriteLine();

             tv = new MyType(10);
            WriteLine("Post-increment");
            Show("Before   ", tv);
            Show("Returned   ", tv++);
            Show("After   ", tv);




        }
    }
    public class MyType            //运行两次，一次是结构，一次是类
    {
        public int X;
        public MyType(int x)
        {
            X = x;
        }
        public static MyType operator ++(MyType m) //++运算符重载
        {
            m.X++;
            return m;
        }
    }
}
